import { createWebHashHistory, createRouter } from 'vue-router'
import Layout from '@/layout'

const modules =
    import.meta.glob("@/views/*/index.vue");

const children = [];
for(const m in modules) {
    const regex = /views(.+?)\/index\.vue/;
    const match = m.match(regex);
    const path = match ? match[1] : "";

    children.push({
        name: path,
        path: path,
        component: modules[m],
    })
}

const routes = [
    {
        path: '/', name: '首页',
        component: Layout,
        redirect: '/index',
        children: children
    },
]

const router = createRouter({
    history: createWebHashHistory(),
    routes: routes
});


export default router;